package com.qfmy.app.controller.novel;

import com.qfmy.app.service.novel.BookService;
import com.qfmy.app.vo.novel.BookVo;
import com.qfmy.common.result.Result;
import com.qfmy.model.annotation.LogAnnotation;
import com.qfmy.model.entity.query.CategoryQuery;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.app.controller.novel
 * @date 2025/4/14
 * @description 小说的控制类
 */
@RestController
@SuppressWarnings("all")
@RequestMapping("/app/novel")
public class BookController {

    /**
     * 注入Autowired
     */
    @Autowired
    private BookService bookService;

    /**
     * 获取小说首页前三排行榜的书籍
     */
    @RequestMapping("/getTopThree")
    public Result<List<BookVo>> getTopThree(){
        List<BookVo> list = bookService.getTopThree();
        return Result.ok(list);
    }

    /**
     * 获取主力推荐的书籍
     */
    @RequestMapping("/getRecommend")
    public Result<List<BookVo>> getRecommend(){
        List<BookVo> list = bookService.getRecommend();
        return Result.ok(list);
    }

    /**
     * 分页获取所有的小说
     */
    @RequestMapping("/getAll")
    public Result<List<BookVo>> getAll(@RequestParam int pageNum, @RequestParam int size){
        List<BookVo> list = bookService.getAll(pageNum,size);
        return Result.ok(list);
    }

    /**
     * 根据类别获取小说
     */
    @LogAnnotation(operation = "根据类别获取小说")
    @RequestMapping("/getByCategory")
    public Result<List<BookVo>> getByCategory(@RequestBody CategoryQuery categoryQuery){
        List<BookVo> list = bookService.getByCategory(categoryQuery);
        return Result.ok(list);
    }

    /**
     * 根据id获取书籍信息
     */
    @LogAnnotation(operation = "根据id获取书籍信息")
    @RequestMapping("/getById")
    public Result<BookVo> getById(@RequestParam Long id){
        BookVo bookVO = bookService.getById(id);
        return Result.ok(bookVO);
    }

    /**
     * 根据不同的标签分页获取数据
     */
    @RequestMapping("/getByTag")
    public Result<List<BookVo>> getByTag(@RequestParam String tag,@RequestParam int pageNum,@RequestParam int size){
        List<BookVo> list = bookService.getByTag(tag,pageNum,size);
        return Result.ok(list);
    }

    /**
     * 搜索小说
     */
    @RequestMapping("/search")
    public Result<List<BookVo>> search(@RequestParam String keyword){
        List<BookVo> list = bookService.search(keyword);
        return Result.ok(list);
    }

    /**
     * 更新收索次数
     */
    @RequestMapping("/searchCount")
    public Result updateSearchCount(@RequestParam Long id){
        bookService.updateSearchCount(id);
        return Result.ok();
    }

    /**
     * 更新阅读次数
     */
    @RequestMapping("/readCount")
    public Result updateReadCount(@RequestParam Long id){
        bookService.updateReadCount(id);
        return Result.ok();
    }

    /**
     * 获取热收索数据
     */
    @RequestMapping("/getHotSearch")
    public Result<List<BookVo>> getHotSearch(@RequestParam int pageNum,@RequestParam int size){
        List<BookVo> list = bookService.getHotSearch(pageNum,size);
        return Result.ok(list);
    }



}
